<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生姓名" prop="studentName">
        <el-input v-model="queryParams.studentName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系方式" prop="studentPhone">
        <el-input v-model="queryParams.studentPhone" placeholder="请输入联系方式" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学生性别" prop="studentGender">
        <el-select v-model="queryParams.studentGender" placeholder="请选择学生性别" clearable>
          <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="学生年级" prop="studentGrade">
        <el-select v-model="queryParams.studentGrade" placeholder="请选择学生年级" clearable>
          <el-option v-for="dict in dict.type.student_grade" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="家教科目" prop="studentParentingSubjects">
        <el-select v-model="queryParams.studentParentingSubjects" placeholder="请选择家教科目" clearable>
          <el-option v-for="dict in dict.type.parenting_subjects" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="家教区域" prop="studentArea">
        <el-select v-model="queryParams.studentArea" placeholder="请选择家教区域" clearable>
          <el-option v-for="dict in dict.type.parenting_area" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="授课方式" prop="studentTeachingMethod">
        <el-select v-model="queryParams.studentTeachingMethod" placeholder="请选择授课方式" clearable>
          <el-option v-for="dict in dict.type.teaching_method" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="家教费用" prop="price">
        <el-select v-model="queryParams.price" placeholder="请选择家教费用" clearable>
          <el-option v-for="dict in dict.type.parenting_expenses" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="参与数量" prop="number">
        <el-select v-model="queryParams.number" placeholder="请选择参与数量" clearable>
          <el-option v-for="dict in dict.type.participants_number" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="家教时间" prop="studentTime">
        <el-input v-model="queryParams.studentTime" placeholder="请输入家教时间" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="详细地址" prop="studentAddress">
        <el-input v-model="queryParams.studentAddress" placeholder="请输入详细地址" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="学员描述" prop="studentDescribe">
        <el-input
          v-model="queryParams.studentDescribe"
          placeholder="请输入学员描述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="教员要求" prop="teacherRequirements">
        <el-input
          v-model="queryParams.teacherRequirements"
          placeholder="请输入教员要求"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="完成状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择完成状态" clearable>
          <el-option v-for="dict in dict.type.completion_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" clearable>
          <el-option v-for="dict in dict.type.audit_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
        </el-form-item>
      <!-- <el-form-item label="${comment}" prop="remark1">
        <el-input
          v-model="queryParams.remark1"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark2">
        <el-input
          v-model="queryParams.remark2"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark3">
        <el-input
          v-model="queryParams.remark3"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark4">
        <el-input
          v-model="queryParams.remark4"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark5">
        <el-input
          v-model="queryParams.remark5"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark6">
        <el-input
          v-model="queryParams.remark6"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark7">
        <el-input
          v-model="queryParams.remark7"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark8">
        <el-input
          v-model="queryParams.remark8"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark9">
        <el-input
          v-model="queryParams.remark9"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark10">
        <el-input
          v-model="queryParams.remark10"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['student:studentlist:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['student:studentlist:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['student:studentlist:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['student:studentlist:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studentlistList" @selection-change="handleSelectionChange" ref="multipleTable">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="学生姓名" align="center" prop="studentName" />
      <el-table-column label="联系方式" align="center" prop="studentPhone" />
      <el-table-column label="学生性别" align="center" prop="studentGender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.studentGender" />
        </template>
      </el-table-column>
      <el-table-column label="学生年级" align="center" prop="studentGrade">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.student_grade" :value="scope.row.studentGrade" />
        </template>
      </el-table-column>
      <el-table-column label="家教科目" align="center" prop="studentParentingSubjects">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.parenting_subjects" :value="scope.row.studentParentingSubjects" />
        </template>
      </el-table-column>
      <el-table-column label="家教区域" align="center" prop="studentArea">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.parenting_area" :value="scope.row.studentArea" />
        </template>
      </el-table-column>
      <el-table-column label="授课方式" align="center" prop="studentTeachingMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.teaching_method" :value="scope.row.studentTeachingMethod" />
        </template>
      </el-table-column>
      <el-table-column label="家教费用" align="center" prop="price">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.parenting_expenses" :value="scope.row.price" />
        </template>
      </el-table-column>
      <el-table-column label="参与数量" align="center" prop="number">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.participants_number" :value="scope.row.number" />
        </template>
      </el-table-column>
      <el-table-column label="家教时间" align="center" prop="studentTime" />
      <el-table-column label="详细地址" align="center" prop="studentAddress" />
      <el-table-column label="学员描述" align="center" prop="studentDescribe" />
      <el-table-column label="教员要求" align="center" prop="teacherRequirements" />
      <el-table-column label="完成状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.completion_status" :value="scope.row.state" />
        </template>
      </el-table-column>
      <el-table-column label="纬度" align="center" prop="remark3" />
      <el-table-column label="经度" align="center" prop="remark4" />
      <el-table-column label="发布时间" align="center" prop="remark1" width="150" />
      <el-table-column label="审核状态" align="center" prop="auditStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.audit_status" :value="scope.row.auditStatus" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="${comment}" align="center" prop="remark2" /> -->
      
      <!-- <el-table-column label="${comment}" align="center" prop="remark5" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark6" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark7" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark8" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark9" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark10" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  >
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['student:studentlist:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['student:studentlist:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改学员列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生姓名" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入学生姓名" />
        </el-form-item>
        <el-form-item label="联系方式" prop="studentPhone">
          <el-input v-model="form.studentPhone" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="学生性别" prop="studentGender">
          <el-select v-model="form.studentGender" placeholder="请选择学生性别">
            <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生年级" prop="studentGrade">
          <el-select v-model="form.studentGrade" placeholder="请选择学生年级">
            <el-option v-for="dict in dict.type.student_grade" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="家教科目" prop="studentParentingSubjects">
          <el-select v-model="form.studentParentingSubjects" placeholder="请选择家教科目">
            <el-option v-for="dict in dict.type.parenting_subjects" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="家教区域" prop="studentArea">
          <el-select v-model="form.studentArea" placeholder="请选择家教区域">
            <el-option v-for="dict in dict.type.parenting_area" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="授课方式" prop="studentTeachingMethod">
          <el-select v-model="form.studentTeachingMethod" placeholder="请选择授课方式">
            <el-option v-for="dict in dict.type.teaching_method" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="家教费用" prop="price">
          <el-select v-model="form.price" placeholder="请选择家教费用">
            <el-option v-for="dict in dict.type.parenting_expenses" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="参与数量" prop="number">
          <el-select v-model="form.number" placeholder="请选择参与数量">
            <el-option v-for="dict in dict.type.participants_number" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="家教时间" prop="studentTime">
          <el-input v-model="form.studentTime" placeholder="请输入家教时间" />
        </el-form-item>
        <el-form-item label="详细地址" prop="studentAddress">
          <el-input v-model="form.studentAddress" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="学员描述" prop="studentDescribe">
          <el-input v-model="form.studentDescribe" placeholder="请输入学员描述" />
        </el-form-item>
        <el-form-item label="教员要求" prop="teacherRequirements">
          <el-input v-model="form.teacherRequirements" placeholder="请输入教员要求" />
        </el-form-item>
        <el-form-item label="完成状态" prop="state">
          <el-select v-model="form.state" placeholder="请选择完成状态">
            <el-option v-for="dict in dict.type.completion_status" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核状态" prop="auditStatus">
          <el-select v-model="form.auditStatus" placeholder="请选择审核状态">
            <el-option v-for="dict in dict.type.audit_status" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item> -->
        <!--  <el-form-item label="${comment}" prop="remark1">
          <el-input v-model="form.remark1" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!-- <el-form-item label="${comment}" prop="remark2">
          <el-input v-model="form.remark2" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!-- <el-form-item label="${comment}" prop="remark3">
          <el-input v-model="form.remark3" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!--  <el-form-item label="${comment}" prop="remark4">
          <el-input v-model="form.remark4" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!-- <el-form-item label="${comment}" prop="remark5">
          <el-input v-model="form.remark5" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!-- <el-form-item label="${comment}" prop="remark6">
          <el-input v-model="form.remark6" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!-- <el-form-item label="${comment}" prop="remark7">
          <el-input v-model="form.remark7" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!-- <el-form-item label="${comment}" prop="remark8">
          <el-input v-model="form.remark8" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!--  <el-form-item label="${comment}" prop="remark9">
          <el-input v-model="form.remark9" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!-- <el-form-item label="${comment}" prop="remark10">
          <el-input v-model="form.remark10" placeholder="请输入${comment}" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listStudentlist,
    getStudentlist,
    delStudentlist,
    addStudentlist,
    updateStudentlist
  } from "@/api/student/studentlist";

  export default {
    name: "Studentlist",
    dicts: ['parenting_subjects', 'completion_status', 'parenting_expenses', 'parenting_area', 'teaching_method',
      'sys_user_sex', 'participants_number', 'student_grade','audit_status'
    ],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 学员列表表格数据
        studentlistList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          studentName: null,
          studentPhone: null,
          studentGender: null,
          studentGrade: null,
          studentParentingSubjects: null,
          studentArea: null,
          studentTeachingMethod: null,
          price: null,
          number: null,
          studentTime: null,
          studentAddress: null,
          studentDescribe: null,
          teacherRequirements: null,
          state: null,
          remark1: null,
          remark2: null,
          remark3: null,
          remark4: null,
          remark5: null,
          remark6: null,
          remark7: null,
          remark8: null,
          remark9: null,
          remark10: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询学员列表列表 */
      getList() {
        this.loading = true;
        listStudentlist(this.queryParams).then(response => {
          this.studentlistList = response.rows;
          this.total = response.total;
          this.loading = false;
         // 重新布局表格
         // this.$nextTick(() => {
         //     this.$refs.multipleTable.doLayout();
         //     // el-table加ref="multipleTable"
         // });
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          studentName: null,
          studentPhone: null,
          studentGender: null,
          studentGrade: null,
          studentParentingSubjects: null,
          studentArea: null,
          studentTeachingMethod: null,
          price: null,
          number: null,
          studentTime: null,
          studentAddress: null,
          studentDescribe: null,
          teacherRequirements: null,
          state: null,
          delFlag: null,
          remark1: null,
          remark2: null,
          remark3: null,
          remark4: null,
          remark5: null,
          remark6: null,
          remark7: null,
          remark8: null,
          remark9: null,
          remark10: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加学员列表";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getStudentlist(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改学员列表";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateStudentlist(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addStudentlist(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除学员列表编号为"' + ids + '"的数据项？').then(function() {
          return delStudentlist(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('student/studentlist/export', {
          ...this.queryParams
        }, `studentlist_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
<style lang="scss" scoped>
  // .el-table__fixed-right {
  //   height: 100% !important;
  // }

  // .el-table__fixed-body-wrapper {  //    max-height: 100% !important;
  // }
</style>
